package com.sl.au.repository;
import java.util.Date;
import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import com.sl.au.entity.EventToEvaluateUser;
import com.sl.au.entity.VisitorReward;

public interface EventToEvaluateUserRepository extends JpaRepository<EventToEvaluateUser, String>  {

	@Query("select e from EventToEvaluateUser e where e.registerEvent.id=?1")
	List<EventToEvaluateUser> findListByEventRegister(String register);
	
	@Query("select e from EventToEvaluateUser e where e.registerUser.id=?1")
	List<EventToEvaluateUser> findListByRegisterUser(String user);
	
	@Query("select e from EventToEvaluateUser e where e.registerEventEvaluateLevel.id=?1")
	List<EventToEvaluateUser> findListByRegisterEventEvaluateLevel(String level);
	
	
	
	@Query("select a from EventToEvaluateUser a where a.createTime >?1 and a.createTime <?2 and a.registerUser.id = ?3")
	Page<EventToEvaluateUser> findByDate(Date begin, Date end, String id, Pageable pageable);
	
	@Query("select a from EventToEvaluateUser a where a.createTime >?1 and a.createTime <?2 and a.registerUser.id = ?3 and a.registerEvent.registerEventName like %?4%")
	Page<EventToEvaluateUser> findByDateAndKey(Date begin, Date end, String id, String key, Pageable pageable);
	
	/*
	 * 部件分析数据详情
	 */
	@Query("select a from EventToEvaluateUser a where a.createTime >?1 and a.createTime <?2 and a.registerUser.id = ?3 and a.registerEvent.registerEventToPartBaseInfo is not null")
	Page<EventToEvaluateUser> findPartByDate(Date begin, Date end, String id, Pageable pageable);
	
	@Query("select a from EventToEvaluateUser a where a.createTime >?1 and a.createTime <?2 and a.registerUser.id = ?3 and a.registerEvent.registerEventToPartBaseInfo is not null and a.registerEvent.registerEventName like %?4%")
	Page<EventToEvaluateUser> findPartByDateAndKey(Date begin, Date end, String id, String key, Pageable pageable);
	
	/*
	 * 非部件分析数据详情
	 */
	@Query("select a from EventToEvaluateUser a where a.createTime >?1 and a.createTime <?2 and a.registerUser.id = ?3 and a.registerEvent.registerEventToPartBaseInfo is null")
	Page<EventToEvaluateUser> findNotPartByDate(Date begin, Date end, String id, Pageable pageable);
	
	@Query("select a from EventToEvaluateUser a where a.createTime >?1 and a.createTime <?2 and a.registerUser.id = ?3 and a.registerEvent.registerEventToPartBaseInfo is null and a.registerEvent.registerEventName like %?4%")
	Page<EventToEvaluateUser> findNotPartByDateAndKey(Date begin, Date end, String id, String key, Pageable pageable);
	
	/*
	 * 具体部件类型分析数据详情
	 */
	@Query("select a from EventToEvaluateUser a where a.createTime >?1 and a.createTime <?2 and a.registerUser.id = ?3 and a.registerEvent.registerEventToPartBaseInfo.id = ?4")
	Page<EventToEvaluateUser> findPartIdByDate(Date begin, Date end, String id, String partId, Pageable pageable);
	
	@Query("select a from EventToEvaluateUser a where a.createTime >?1 and a.createTime <?2 and a.registerUser.id = ?3 and a.registerEvent.registerEventToPartBaseInfo.id = ?4 and a.registerEvent.registerEventName like %?5%")
	Page<EventToEvaluateUser> findPartIdByDateAndKey(Date begin, Date end, String id, String partId, String key, Pageable pageable);
	
	/*
	 * 具体事件类型分析数据详情
	 */
	@Query("select a from EventToEvaluateUser a where a.createTime >?1 and a.createTime <?2 and a.registerUser.id = ?3 and a.registerEvent.registerEventType.id = ?4")
	Page<EventToEvaluateUser> findEventIdByDate(Date begin, Date end, String id, String partId, Pageable pageable);
	
	@Query("select a from EventToEvaluateUser a where a.createTime >?1 and a.createTime <?2 and a.registerUser.id = ?3 and a.registerEvent.registerEventType.id = ?4 and a.registerEvent.registerEventName like %?5%")
	Page<EventToEvaluateUser> findEventIdByDateAndKey(Date begin, Date end, String id, String partId, String key, Pageable pageable);
	
	/*
	 * 具体网格分析数据详情
	 */
	@Query("select a from EventToEvaluateUser a where a.createTime >?1 and a.createTime <?2 and a.registerUser.id = ?3 and a.registerEvent.registerEventToNetGrid.id = ?4")
	Page<EventToEvaluateUser> findGridIdByDate(Date begin, Date end, String id, String partId, Pageable pageable);
	
	@Query("select a from EventToEvaluateUser a where a.createTime >?1 and a.createTime <?2 and a.registerUser.id = ?3 and a.registerEvent.registerEventToNetGrid.id = ?4 and a.registerEvent.registerEventName like %?5%")
	Page<EventToEvaluateUser> findGridIdByDateAndKey(Date begin, Date end, String id, String partId, String key, Pageable pageable);
	
	/*
	 * 具体区域分析数据详情
	 */
	@Query("select a from EventToEvaluateUser a where a.createTime >?1 and a.createTime <?2 and a.registerUser.id = ?3 and a.registerEvent.registerEventToNetGrid.division.id = ?4")
	Page<EventToEvaluateUser> findDivisionIdByDate(Date begin, Date end, String id, String partId, Pageable pageable);
	
	@Query("select a from EventToEvaluateUser a where a.createTime >?1 and a.createTime <?2 and a.registerUser.id = ?3 and a.registerEvent.registerEventToNetGrid.division.id = ?4 and a.registerEvent.registerEventName like %?5%")
	Page<EventToEvaluateUser> findDivisionIdByDateAndKey(Date begin, Date end, String id, String partId, String key, Pageable pageable);
	
	@Query("select a from EventToEvaluateUser a where a.registerUser.id=?1 and a.createTime > ?2 and a.createTime <?3 order by a.createTime desc")
	List<EventToEvaluateUser> getUserScoreListByDate(String userId, Date begin, Date end);
}
